package com.ctshk.rpc.order.airexpress.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.IsDeletedCode;
import com.ctshk.common.enums.OrderScheduledStatus;
import com.ctshk.common.enums.SystemBusinessType;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.mail.bo.Attachment;
import com.ctshk.common.mail.core.MailTemplate;
import com.ctshk.common.sms.core.SmsUtil;
import com.ctshk.common.utils.CharUtil;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.common.utils.freemarker.FreemarkerUtil;
import com.ctshk.rpc.airexpress.dto.AirportExpressInfoDTO;
import com.ctshk.rpc.airexpress.service.IAirportExpressService;
import com.ctshk.rpc.order.airexpress.constants.AirportExpressConstants;
import com.ctshk.rpc.order.airexpress.dto.*;
import com.ctshk.rpc.order.airexpress.entity.AirportExpressOrder;
import com.ctshk.rpc.order.airexpress.entity.AirportExpressOrderCollection;
import com.ctshk.rpc.order.airexpress.entity.AirportExpressOrderReceipt;
import com.ctshk.rpc.order.airexpress.entity.AirportExpressOrderTourist;
import com.ctshk.rpc.order.airexpress.enums.AttachmentEnum;
import com.ctshk.rpc.order.airexpress.mapper.AirportExpressOrderCollectionMapper;
import com.ctshk.rpc.order.airexpress.mapper.AirportExpressOrderMapper;
import com.ctshk.rpc.order.airexpress.mapper.AirportExpressOrderReceiptMapper;
import com.ctshk.rpc.order.airexpress.mapper.AirportExpressOrderTouristMapper;
import com.ctshk.rpc.order.airexpress.req.AirportExpressOrderReceiptDownloadReq;
import com.ctshk.rpc.order.airexpress.req.AirportExpressOrderReceiptInformEmailReq;
import com.ctshk.rpc.order.airexpress.req.AirportExpressOrderReceiptSaveReq;
import com.ctshk.rpc.order.airexpress.service.IAirportExpressOrderReceiptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.rpc.system.service.IFileOSSService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.mail.MessagingException;
import java.io.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

import static com.ctshk.common.utils.SeasonOrderManager.MTR_AGENT_ID;

/**
 * <p>
 * 机场快线订单收据 服务实现类
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-22
 */
@Slf4j
@DubboService
public class AirportExpressOrderReceiptServiceImpl extends ServiceImpl<AirportExpressOrderReceiptMapper, AirportExpressOrderReceipt> implements IAirportExpressOrderReceiptService {
    @Autowired
    AirportExpressOrderReceiptMapper airportExpressOrderReceiptMapper;
    @Autowired
    AirportExpressOrderMapper airportExpressOrderMapper;
    @Autowired
    AirportExpressOrderCollectionMapper airportExpressOrderCollectionMapper;
    @Autowired
    AirportExpressOrderTouristMapper airportExpressOrderTouristMapper;
    @DubboReference
    IAirportExpressService airportExpressService;
    @DubboReference
    IFileOSSService fileOSSService;
    @Autowired
    MailTemplate mailTemplate;

    private String classPath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
    private String splitPath = classPath.replace("file:", "").split("target")[0];
    private String templatePath = splitPath + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "template";

    @Override
    public int update(AirportExpressOrderReceiptSaveReq airportExpressOrderReceiptSaveReq, Long userId) {
        QueryWrapper<AirportExpressOrderReceipt> receiptQueryWrapper = new QueryWrapper<>();
        receiptQueryWrapper.lambda().eq(AirportExpressOrderReceipt::getOrderId, airportExpressOrderReceiptSaveReq.getOrderId());
        AirportExpressOrderReceipt airportExpressOrderReceiptTemp = airportExpressOrderReceiptMapper.selectOne(receiptQueryWrapper);
        if (airportExpressOrderReceiptTemp == null) {
            //该订单不存在收据
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60026);
        }
        AirportExpressOrderReceipt airportExpressOrderReceipt = EntityUtil.copy(airportExpressOrderReceiptSaveReq, AirportExpressOrderReceipt.class);
        UpdateWrapper<AirportExpressOrderReceipt> receiptUpdateWrapper = new UpdateWrapper<>();
        receiptUpdateWrapper.lambda().eq(AirportExpressOrderReceipt::getOrderId, airportExpressOrderReceipt.getOrderId());
        receiptUpdateWrapper.lambda().set(AirportExpressOrderReceipt::getGuest, airportExpressOrderReceipt.getGuest());
        receiptUpdateWrapper.lambda().set(AirportExpressOrderReceipt::getPhone, airportExpressOrderReceipt.getPhone());
        receiptUpdateWrapper.lambda().set(AirportExpressOrderReceipt::getAttention, airportExpressOrderReceipt.getAttention());
        receiptUpdateWrapper.lambda().set(AirportExpressOrderReceipt::getRemark, airportExpressOrderReceipt.getRemark());
        receiptUpdateWrapper.lambda().set(AirportExpressOrderReceipt::getModifiedId, userId);
        receiptUpdateWrapper.lambda().set(AirportExpressOrderReceipt::getGmtModified, LocalDateTime.now());
        int updateNum = airportExpressOrderReceiptMapper.update(null, receiptUpdateWrapper);
        return updateNum;
    }

    @Override
    public AirportExpressOrderReceiptGetDTO getReceiptByOrderId(Long orderId) {
        AirportExpressOrder airportExpressOrder = airportExpressOrderMapper.selectById(orderId);
        if (airportExpressOrder == null) {
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60002);
        }
        QueryWrapper<AirportExpressOrderReceipt> receiptQueryWrapper = new QueryWrapper<>();
        receiptQueryWrapper.lambda().eq(AirportExpressOrderReceipt::getOrderId, orderId);
        AirportExpressOrderReceipt airportExpressOrderReceiptTemp = airportExpressOrderReceiptMapper.selectOne(receiptQueryWrapper);
        if (airportExpressOrderReceiptTemp == null) {
            //该订单不存在收据
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60026);
        }
        /**
         * info
         */
        AirportExpressOrderReceiptGetDTO airportExpressOrderReceiptGetDTO = EntityUtil.copy(airportExpressOrderReceiptTemp, AirportExpressOrderReceiptGetDTO.class);
        airportExpressOrderReceiptGetDTO.setInquiryNumber(airportExpressOrder.getInquiryNumber());
        airportExpressOrderReceiptGetDTO.setReceiptNo(airportExpressOrderReceiptTemp.getReceiptNo());
        airportExpressOrderReceiptGetDTO.setGuest(airportExpressOrderReceiptTemp.getGuest());
        airportExpressOrderReceiptGetDTO.setPhone(airportExpressOrderReceiptTemp.getPhone());
        airportExpressOrderReceiptGetDTO.setOrderInfo(airportExpressOrder.getTicketTypeName());
        /**
         * 内容Detail
         */
        ArrayList<AirportExpressOrderTouristReceiptGetDTO> airportExpressOrderTouristReceiptGetDTOS = new ArrayList<>();
        airportExpressOrderReceiptGetDTO.setAirportExpressOrderTouristReceiptGetDTOList(airportExpressOrderTouristReceiptGetDTOS);
        if (airportExpressOrder.getAdultTicketNumber() > 0) {
            AirportExpressOrderTouristReceiptGetDTO airportExpressOrderTouristReceiptGetDTO = new AirportExpressOrderTouristReceiptGetDTO();
            airportExpressOrderTouristReceiptGetDTO.setTicketName(airportExpressOrder.getTicketTypeName());
            airportExpressOrderTouristReceiptGetDTO.setTicketType("成人");
            airportExpressOrderTouristReceiptGetDTO.setTicketNumber(airportExpressOrder.getAdultTicketNumber());
            airportExpressOrderTouristReceiptGetDTO.setTicketPrice(airportExpressOrder.getAdultPrice());
            airportExpressOrderTouristReceiptGetDTO.setTicketPriceTotal(airportExpressOrder.getAdultPrice().multiply(new BigDecimal(airportExpressOrder.getAdultTicketNumber())));
            airportExpressOrderTouristReceiptGetDTO.setDate(airportExpressOrder.getEffectiveTime());
            airportExpressOrderTouristReceiptGetDTOS.add(airportExpressOrderTouristReceiptGetDTO);
        }
        if (airportExpressOrder.getChildrenTicketNumber() != null && airportExpressOrder.getChildrenTicketNumber() > 0) {
            AirportExpressOrderTouristReceiptGetDTO airportExpressOrderTouristReceiptGetDTO = new AirportExpressOrderTouristReceiptGetDTO();
            airportExpressOrderTouristReceiptGetDTO.setTicketName(airportExpressOrder.getTicketTypeName());
            airportExpressOrderTouristReceiptGetDTO.setTicketType("小童");
            airportExpressOrderTouristReceiptGetDTO.setTicketNumber(airportExpressOrder.getChildrenTicketNumber());
            airportExpressOrderTouristReceiptGetDTO.setTicketPrice(airportExpressOrder.getChildrenPrice());
            airportExpressOrderTouristReceiptGetDTO.setTicketPriceTotal(airportExpressOrder.getChildrenPrice().multiply(new BigDecimal(airportExpressOrder.getChildrenTicketNumber())));
            airportExpressOrderTouristReceiptGetDTO.setDate(airportExpressOrder.getEffectiveTime());
            airportExpressOrderTouristReceiptGetDTOS.add(airportExpressOrderTouristReceiptGetDTO);
        }
        /**
         * 支付详情
         */
        airportExpressOrderReceiptGetDTO.setOrderAmount(airportExpressOrder.getOrderAmount());
        airportExpressOrderReceiptGetDTO.setReceivableAmount(airportExpressOrder.getReceivableAmount());
        QueryWrapper<AirportExpressOrderCollection> collectionQueryWrapper = new QueryWrapper<>();
        collectionQueryWrapper.lambda().eq(AirportExpressOrderCollection::getOrderId, orderId);
        collectionQueryWrapper.lambda().eq(AirportExpressOrderCollection::getIsDeleted, IsDeletedCode.NO.getCode());
        List<AirportExpressOrderCollection> airportExpressOrderCollections = airportExpressOrderCollectionMapper.selectList(collectionQueryWrapper);
        List<AirportExpressOrderCollectionReceiptGetDTO> airportExpressOrderCollectionReceiptGetDTOS = EntityUtil.copyList(airportExpressOrderCollections, AirportExpressOrderCollectionReceiptGetDTO.class);
        airportExpressOrderReceiptGetDTO.setAirportExpressOrderCollectionReceiptGetDTOList(airportExpressOrderCollectionReceiptGetDTOS);
        /**
         * 预订须知
         */
        AirportExpressInfoDTO airportExpressInfoDTO = airportExpressService.selectInfo(airportExpressOrder.getAirportExpressId());
        airportExpressOrderReceiptGetDTO.setBookingInformation(airportExpressInfoDTO.getBookingInformation());
        return airportExpressOrderReceiptGetDTO;
    }

    @Override
    public List<AirportExpressOrderETicketGetDTO> getETicketByOrderId(Long orderId) {
        AirportExpressOrder airportExpressOrder = airportExpressOrderMapper.selectById(orderId);
        if (airportExpressOrder == null) {
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60002);
        }
        QueryWrapper<AirportExpressOrderTourist> TouristQueryWrapper = new QueryWrapper<>();
        TouristQueryWrapper.lambda().eq(AirportExpressOrderTourist::getOrderId, orderId);
        List<AirportExpressOrderTourist> airportExpressOrderTouristList = airportExpressOrderTouristMapper.selectList(TouristQueryWrapper);
        if (CollectionUtils.isEmpty(airportExpressOrderTouristList)) {
            //该订单不存在收据
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60026);
        }
        /**
         * 预订须知
         */
        AirportExpressInfoDTO airportExpressInfoDTO = airportExpressService.selectInfo(airportExpressOrder.getAirportExpressId());
        List<AirportExpressOrderETicketGetDTO> airportExpressOrderETicketGetDTOList = new ArrayList<>();
        for (AirportExpressOrderTourist airportExpressOrderTourist : airportExpressOrderTouristList) {
            AirportExpressOrderETicketGetDTO airportExpressOrderETicketGetDTO = EntityUtil.copy(airportExpressOrder, AirportExpressOrderETicketGetDTO.class);
            airportExpressOrderETicketGetDTO.setAgentId(MTR_AGENT_ID);
            airportExpressOrderETicketGetDTO.setTicketTypeNameCn(airportExpressInfoDTO.getTicketTypeNameCn());
            airportExpressOrderETicketGetDTO.setTicketTypeNameEn(airportExpressInfoDTO.getTicketTypeNameEn());
            airportExpressOrderETicketGetDTO.setBookingInformation(airportExpressInfoDTO.getBookingInformation());
            System.out.println(airportExpressInfoDTO.getBookingInformation()); //test
            airportExpressOrderETicketGetDTO.setTicketNumber(airportExpressOrderTourist.getThirdTicketNumber());
            //二维码
            airportExpressOrderETicketGetDTO.setTicketQrCodeUrl(airportExpressOrderTourist.getThirdTicketQrCodeUrl());
            if (airportExpressOrderTourist.getTouristType() == 1) {//成人
                airportExpressOrderETicketGetDTO.setTicketTouristType("成人");
            } else {//小童
                airportExpressOrderETicketGetDTO.setTicketTouristType("小童");
            }
            airportExpressOrderETicketGetDTOList.add(airportExpressOrderETicketGetDTO);
        }
        return airportExpressOrderETicketGetDTOList;
    }

    @Override
    public AirportExpressOrderDownloadDTO download(AirportExpressOrderReceiptDownloadReq downloadReq) {
        AirportExpressOrder airportExpressOrder = airportExpressOrderMapper.selectById(downloadReq.getOrderId());
        if (airportExpressOrder == null) {
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60002);
        }
        HashMap data = new HashMap();
        data.put("order", airportExpressOrder);
        if (downloadReq.getType().equals(AttachmentEnum.E_TICKET.getNameEn())) {
            data.put("type", AttachmentEnum.E_TICKET.getName());
            return getAttachmentBytes(downloadReq.getOrderId(), data, AttachmentEnum.E_TICKET);
        } else if (downloadReq.getType().equals(AttachmentEnum.RECEIPT.getNameEn())) {
            data.put("type", AttachmentEnum.RECEIPT.getName());
            return getAttachmentBytes(downloadReq.getOrderId(), data, AttachmentEnum.RECEIPT);
        }
        return null;
    }

    @Override
    public Result sendReceiptByOrderId(Long orderId) {
        AirportExpressOrder airportExpressOrder = airportExpressOrderMapper.selectById(orderId);
        if (airportExpressOrder == null) {
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60002);
        }
        String subject = "【港中旅】香港機場快線 " + airportExpressOrder.getTicketTypeName() + AttachmentEnum.RECEIPT.getName();
        // email content
        HashMap data = new HashMap();
        data.put("type", AttachmentEnum.RECEIPT.getName());
        data.put("order", airportExpressOrder);
        String content = null;
        try {
            content = FreemarkerUtil.createHtml(data, templatePath, "airportexpress_email.ftl");
            /**
             * 生成pdf附件
             */
            AirportExpressOrderDownloadDTO downloadDTO = getAttachmentBytes(orderId, data, AttachmentEnum.RECEIPT);
            byte[] receiptBytes = downloadDTO.getFileBytes();
            mailTemplate.sendAttachmentMail(airportExpressOrder.getContactEmail(), subject, content, "receipt.pdf", receiptBytes);
        } catch (MessagingException e) {
            log.error("【机场快线-发送收据】发送邮件失败,error:{}", e.getMessage(), e);
            return Result.failed(SystemError.SYS_437);
        } catch (Exception e) {
            log.error("【机场快线-发送收据】发送邮件失败,error:{}", e.getMessage(), e);
            return Result.failed(SystemError.SYS_437);
        }
        return Result.success();
    }


    @Override
    public Result sendETicketByOrderId(Long orderId) {
        AirportExpressOrder airportExpressOrder = airportExpressOrderMapper.selectById(orderId);
        if (airportExpressOrder == null) {
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60002);
        }
        // title
        String subject = "【港中旅】香港機場快線 " + airportExpressOrder.getTicketTypeName() + AttachmentEnum.E_TICKET.getName();
        // email content
        HashMap data = new HashMap();
        data.put("type", AttachmentEnum.E_TICKET.getName());
        data.put("order", airportExpressOrder);
        String content = null;
        try {
            content = FreemarkerUtil.createHtml(data, templatePath, "airportexpress_email.ftl");
            /**
             * 生成pdf附件
             */
            AirportExpressOrderDownloadDTO downloadDTO = getAttachmentBytes(orderId, data, AttachmentEnum.E_TICKET);
            byte[] pdfBytes = downloadDTO.getFileBytes();
            mailTemplate.sendAttachmentMail(airportExpressOrder.getContactEmail(), subject, content, "e-ticket.pdf", pdfBytes);
        } catch (MessagingException e) {
            log.error("【机场快线-发送电子票】发送邮件失败,error:{}", e.getMessage(), e);
            return Result.failed(SystemError.SYS_437);
        } catch (Exception e) {
            log.error("【机场快线-发送电子票】发送邮件失败,error:{}", e.getMessage(), e);
            return Result.failed(SystemError.SYS_437);
        }
        return Result.success();
    }

    @Override
    public Result sendInformByOrderId(AirportExpressOrderReceiptInformEmailReq orderReceiptInformEmailReq) {
        AirportExpressOrder airportExpressOrder = airportExpressOrderMapper.selectById(orderReceiptInformEmailReq.getOrderId());
        if (airportExpressOrder == null) {
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60002);
        }
        if (airportExpressOrder.getScheduledStatus() == null && airportExpressOrder.getScheduledStatus() < OrderScheduledStatus.CONFIRM_RESERVE.getCode()) {
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60002);
        }
        Result result = Result.success();
        if (Objects.equals(1, orderReceiptInformEmailReq.getInformType())) {
            result = sendEmailInform(orderReceiptInformEmailReq, airportExpressOrder);
        } else {
            HashMap<String, String> paramMap = new HashMap<>();
            paramMap.put("namevotes", airportExpressOrder.getTicketTypeName());
            paramMap.put("use", orderReceiptInformEmailReq.getPhoneContent());
            paramMap.put("service", "(852)2998 7888");
            boolean domestic = CharUtil.isDomestic(orderReceiptInformEmailReq.getPhoneContent());
            try {
                SmsUtil.sendSms(orderReceiptInformEmailReq.getPhone(), "SMS_215980892", paramMap);
            } catch (Exception e) {
                log.error("【机场快线订单收据】发送短信失败,error:{}", e);
                throw new BusinessException(SystemError.AIREXPRESS_ORDER_60037, e.getMessage());
//                return Result.failed(new BusinessException(SystemError.AIREXPRESS_ORDER_60037, e.getMessage()));
            }
        }
        return result;
    }

    private Result sendEmailInform(AirportExpressOrderReceiptInformEmailReq airportExpressOrderReceiptInformEmailReq, AirportExpressOrder airportExpressOrder) {
        // title
        String subject = "【港中旅】香港機場快線 " + airportExpressOrder.getTicketTypeName() + " 通知";
        // email content
        String type;
        if (Objects.equals(airportExpressOrder.getScheduledStatus(), OrderScheduledStatus.RESERVE_SUCCESS.getCode()) && airportExpressOrder.getCancelStatus() == null) {
            type = AttachmentEnum.RECEIPT.getName() + "、" + AttachmentEnum.E_TICKET.getName();
        } else {
            type = AttachmentEnum.RECEIPT.getName();
        }
        HashMap data = new HashMap();
        data.put("type", type);
        data.put("order", airportExpressOrder);
        String content = null;
        List<Attachment> attachmentList = new ArrayList<>();
        try {
            content = FreemarkerUtil.createHtml(data, templatePath, "airportexpress_email.ftl");
            /**
             * 生成pdf附件
             */
            AirportExpressOrderDownloadDTO receiptDTO = getAttachmentBytes(airportExpressOrder.getId(), data, AttachmentEnum.RECEIPT);
            attachmentList.add(new Attachment(receiptDTO.getFullName(), receiptDTO.getFileBytes()));
            AirportExpressOrderDownloadDTO eTicketDTO = getAttachmentBytes(airportExpressOrder.getId(), data, AttachmentEnum.E_TICKET);
            attachmentList.add(new Attachment(eTicketDTO.getFullName(), eTicketDTO.getFileBytes()));

            mailTemplate.sendAttachmentsMail(airportExpressOrderReceiptInformEmailReq.getToEmail(), subject, content, attachmentList);
        } catch (BusinessException e) {
            log.error("【机场快线-旅客通知-邮件】发送旅客通知失败,error:{}", e.getMessage(), e);
            return Result.failed(SystemError.getDefined(e.getCode()));
        } catch (Exception e) {
            log.error("【机场快线-旅客通知-邮件】发送旅客通知失败,error:{}", e.getMessage(), e);
            return Result.failed(SystemError.SYS_437);
        }
        return Result.success();
    }


    /**
     * 查询OSS服务器的收据PDF文件，不存在就生成并上传，并且返回文件字节码
     *
     * @param orderId
     * @param data
     * @param attachmentEnum
     * @return
     */
    private AirportExpressOrderDownloadDTO getAttachmentBytes(Long orderId, HashMap data, AttachmentEnum attachmentEnum) {
        String fullName;
        String templateFileName;
        if (attachmentEnum == AttachmentEnum.RECEIPT) {//收据
            fullName = getReceiptFullName(orderId);
            templateFileName = "airportexpress_receipt.ftl";
        } else {//电子票
            fullName = getETicketFullName(orderId);
            templateFileName = "airportexpress_e-ticket.ftl";
        }

        // 查询OSS服务器上的文件
        try {
            Result findResult = fileOSSService.findObject(fullName);
            if (findResult.isSuccess()) {
                return new AirportExpressOrderDownloadDTO(fullName, (byte[]) findResult.getData(), "");
            }
        } catch (Exception e) {
            log.error("【机场快线收据-获取附件】OSS查询异常,error:{}", e.getMessage(), e);
        }

        if (attachmentEnum == AttachmentEnum.RECEIPT) {
            AirportExpressOrderReceiptGetDTO airportExpressOrderReceiptGetDTO = getReceiptByOrderId(orderId);
            data.put("receipt", airportExpressOrderReceiptGetDTO);
        } else if (attachmentEnum == AttachmentEnum.E_TICKET) {
            List<AirportExpressOrderETicketGetDTO> airportExpressOrderETicketGetDTOList = getETicketByOrderId(orderId);
            data.put("list", airportExpressOrderETicketGetDTOList);
        }

        // 生成pdf并上传
        byte[] pdfBytes = new byte[0];
        String pdfString = null;
        try {
            ByteArrayOutputStream pdfOutPut = FreemarkerUtil.createPDF(data, templatePath, templateFileName);
            pdfBytes = pdfOutPut.toByteArray();
            pdfString = pdfOutPut.toString();
            log.info("【机场快线收据-获取附件】生成pdf成功, pdf字节长度:{}", pdfBytes.length);
            fileOSSService.upload(fullName, pdfBytes, SystemBusinessType.AIR_EXPRESS.getCode());
            log.info("【机场快线收据-获取附件】上传pdf成功");
        } catch (Exception e) {
            log.error("【机场快线收据-获取附件】生成pdf异常,error:{}", e.getMessage(), e);
        }
        return new AirportExpressOrderDownloadDTO(fullName, pdfBytes, pdfString);
    }

    // 获取收据PDF全名
    private String getReceiptFullName(Long orderId) {
        return "airportexpress-receipt-" + orderId + ".pdf";
    }

    // 获取电子票PDF全名
    private String getETicketFullName(Long orderId) {
        return "airportexpress-eticket-" + orderId + ".pdf";
    }
}
